package com.qzxy.premiumhotelsystem.service.impl;

import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qzxy.premiumhotelsystem.common.constant.UserRoleConstant;
import com.qzxy.premiumhotelsystem.domain.entity.Employees;
import com.qzxy.premiumhotelsystem.domain.vo.EmployeeInfoVo;
import com.qzxy.premiumhotelsystem.domain.vo.LoginVo;
import com.qzxy.premiumhotelsystem.mapper.EmployeesMapper;
import com.qzxy.premiumhotelsystem.mapper.LogsMapper;
import com.qzxy.premiumhotelsystem.common.result.Result;
import com.qzxy.premiumhotelsystem.service.EmployeesService;
import com.qzxy.premiumhotelsystem.utils.Bcrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.qzxy.premiumhotelsystem.config.SaTokenConfig.employeeStpLogic;
import static com.qzxy.premiumhotelsystem.common.result.ResultCodeEnum.PASSWORD_ERROR;
import static com.qzxy.premiumhotelsystem.common.result.ResultCodeEnum.USERNAME_ERROR;

/**
* @author 14912
* @description 针对表【employees】的数据库操作Service实现
* @createDate 2024-09-12 15:55:14
*/
@Service
public class EmployeesServiceImpl extends ServiceImpl<EmployeesMapper, Employees>
    implements EmployeesService{

    @Autowired
    private EmployeesMapper employeesMapper;
    @Autowired
    private LogsMapper logsMapper;
    @Autowired
    private Bcrypt bcrypt;
    @Value("${user.alioss.endpoint}")
    String endpoint;
    @Value("${user.alioss.bucket-name}")
    String bucketName;

    @Override
    public String login(LoginVo loginVo) {
        return employeesMapper.login(loginVo);
    }

    /**
     * 根据手机号删除员工
     * @param telephone
     * @return
     */
    @Override
    public boolean deleteByTelephoneBoolean(String telephone) {
        return employeesMapper.deleteByTelephoneBoolean(telephone);
    }

    @Override
    public Employees getByTelephone(String telephone) {
        return employeesMapper.getByTelephone(telephone);
    }

    @Override
    public Employees getByEmail(String email) {
        return employeesMapper.getByEmail(email);
    }

    @Override
    public List<Employees> allEmployees() {
        return employeesMapper.allEmployees();
    }

    /**
     * 分页查询员工
     * @param pageSize
     * @param limit
     * @return
     */
    @Override
    public PageInfo<Employees> allEmployeesForPage(Integer pageSize, Integer limit) {
        Page<Employees> page = PageHelper.startPage(pageSize, limit);
        List<Employees> employees = employeesMapper.allEmployees();
        return page.toPageInfo();
    }

    @Override
    public boolean updateLoginStatus(String loginIp, String loginTime, String telephone) {
        return employeesMapper.updateLoginStatus(loginIp,loginTime,telephone);
    }

    @Override
    public boolean updateInformation(EmployeeInfoVo employeeInfoVo) {
        boolean b = employeesMapper.updateInformation(employeeInfoVo);
        String msg= b != false ? "更新用户基本信息成功" : "更新用户基本信息失败";
//        logsMapper.create(employeeInfoVo.getTelephone(), msg);
        return b;
    }

    /**
     * 更新员工状态
     * @param telephone
     * @param status
     * @return
     */
    @Override
    public boolean updateStatue(String telephone,String status) {
        boolean b = employeesMapper.updateStatue(telephone,status);
        String msg= b != false ? "更新用户状态成功" : "更新用户状态失败";
//        logsMapper.create(telephone, msg);
        return b;
    }

    /**
     * 功能描述：
     *
     * @param url
     * @param telephone
     * @return {@link Boolean }
     * @author iQNRen
     * @date 2024/09/19
     */

    @Override
    public Boolean uploadAvatar(String url, String telephone) {
        return employeesMapper.uploadAvatar(url,telephone);
    }


}




